<template>
  <el-dialog
    :title="!dataForm.jobLogId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="任务名称" prop="jobName">
      <el-input v-model="dataForm.jobName" placeholder="任务名称"></el-input>
    </el-form-item>
    <el-form-item label="任务组名" prop="jobGroup">
      <el-input v-model="dataForm.jobGroup" placeholder="任务组名"></el-input>
    </el-form-item>
    <el-form-item label="调用目标字符串" prop="invokeTarget">
      <el-input v-model="dataForm.invokeTarget" placeholder="调用目标字符串"></el-input>
    </el-form-item>
    <el-form-item label="日志信息" prop="jobMessage">
      <el-input v-model="dataForm.jobMessage" placeholder="日志信息"></el-input>
    </el-form-item>
    <el-form-item label="执行状态（0正常 1失败）" prop="status">
      <el-input v-model="dataForm.status" placeholder="执行状态（0正常 1失败）"></el-input>
    </el-form-item>
    <el-form-item label="异常信息" prop="exceptionInfo">
      <el-input v-model="dataForm.exceptionInfo" placeholder="异常信息"></el-input>
    </el-form-item>
    <el-form-item label="创建者" prop="createBy">
      <el-input v-model="dataForm.createBy" placeholder="创建者"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新者" prop="updateBy">
      <el-input v-model="dataForm.updateBy" placeholder="更新者"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="备注信息" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注信息"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          jobLogId: 0,
          jobName: '',
          jobGroup: '',
          invokeTarget: '',
          jobMessage: '',
          status: '',
          exceptionInfo: '',
          createBy: '',
          createTime: '',
          updateBy: '',
          updateTime: '',
          remark: ''
        },
        dataRule: {
          jobName: [
            { required: true, message: '任务名称不能为空', trigger: 'blur' }
          ],
          jobGroup: [
            { required: true, message: '任务组名不能为空', trigger: 'blur' }
          ],
          invokeTarget: [
            { required: true, message: '调用目标字符串不能为空', trigger: 'blur' }
          ],
          jobMessage: [
            { required: true, message: '日志信息不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '执行状态（0正常 1失败）不能为空', trigger: 'blur' }
          ],
          exceptionInfo: [
            { required: true, message: '异常信息不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '创建者不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateBy: [
            { required: true, message: '更新者不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注信息不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.jobLogId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.jobLogId) {
            this.$http({
              url: this.$http.adornUrl(`/ruoyiapisystem/sysjoblog/info/${this.dataForm.jobLogId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.jobName = data.sysJobLog.jobName
                this.dataForm.jobGroup = data.sysJobLog.jobGroup
                this.dataForm.invokeTarget = data.sysJobLog.invokeTarget
                this.dataForm.jobMessage = data.sysJobLog.jobMessage
                this.dataForm.status = data.sysJobLog.status
                this.dataForm.exceptionInfo = data.sysJobLog.exceptionInfo
                this.dataForm.createBy = data.sysJobLog.createBy
                this.dataForm.createTime = data.sysJobLog.createTime
                this.dataForm.updateBy = data.sysJobLog.updateBy
                this.dataForm.updateTime = data.sysJobLog.updateTime
                this.dataForm.remark = data.sysJobLog.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/ruoyiapisystem/sysjoblog/${!this.dataForm.jobLogId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'jobLogId': this.dataForm.jobLogId || undefined,
                'jobName': this.dataForm.jobName,
                'jobGroup': this.dataForm.jobGroup,
                'invokeTarget': this.dataForm.invokeTarget,
                'jobMessage': this.dataForm.jobMessage,
                'status': this.dataForm.status,
                'exceptionInfo': this.dataForm.exceptionInfo,
                'createBy': this.dataForm.createBy,
                'createTime': this.dataForm.createTime,
                'updateBy': this.dataForm.updateBy,
                'updateTime': this.dataForm.updateTime,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
